package com.booksystem.campuslibrarymanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booksystem.campuslibrarymanagementsystem.entity.AccountTable;
import com.booksystem.campuslibrarymanagementsystem.entity.BooksTable;
import com.booksystem.campuslibrarymanagementsystem.entity.CategoriesTable;
import com.booksystem.campuslibrarymanagementsystem.entity.UserTable;
import com.booksystem.campuslibrarymanagementsystem.mapper.AccountTableMapper;
import com.booksystem.campuslibrarymanagementsystem.mapper.BooksTableMapper;
import com.booksystem.campuslibrarymanagementsystem.service.BooksTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BooksTableServiceImpl extends ServiceImpl<BooksTableMapper, BooksTable> implements BooksTableService {
    @Autowired
    BooksTableMapper booksTableMapper;

    @Override
    public BooksTable queryById(int bookid) {
        return booksTableMapper.queryById(bookid);
    }

    @Override
    public boolean upDataBook(int bookid, String title, String author, String category) {
        return booksTableMapper.upDataBook(bookid,title,author,category);
    }

    @Override
    public List<BooksTable> selectBybooktitle(String title) {
        return booksTableMapper.selectBybooktitle(title);
    }

    @Override
    public BooksTable queryByTitle(String title) {
        return booksTableMapper.queryByTitle(title);
    }


    @Override
    public boolean deleteByBookid(int bookid) {
        return booksTableMapper.deleteByBookid(bookid);
    }

    @Override
    public BooksTable selectLastBookid() {
        return booksTableMapper.selectLastBookid();
    }

    @Override
    public List<BooksTable> selectList(int bookid, String title, String author, String category) {
        QueryWrapper<BooksTable> queryWrapper = new QueryWrapper<>();
        if (bookid != 0) {
            queryWrapper.like("bookid", bookid);
        }
        if (title != null && !title.isEmpty()) {
            // 对标题进行模糊查询，假设我们希望标题中包含输入的字符串
            queryWrapper.like("title", title);
        }
        if (author != null && !author.isEmpty()) {
            // 对作者进行模糊查询
            queryWrapper.like("author", author);
        }
        if (category != null && !category.isEmpty()) {
            queryWrapper.like("category", category); // 类别仍使用精确匹配
        }
        return booksTableMapper.selectList(queryWrapper);
    }

    @Override
    public boolean AddBook(int bookid, int totalcopies) {
        return booksTableMapper.AddBook(bookid,totalcopies);
    }


    @Override
    public   BooksTable add(int bookid){
        return booksTableMapper.add(bookid);
    }


    @Override
    public List<BooksTable> selectbookList(String title, String author, String category) {
        QueryWrapper<BooksTable> queryWrapper = new QueryWrapper<>();
        if (title != null && !title.isEmpty()) {
            // 对标题进行模糊查询，假设我们希望标题中包含输入的字符串
            queryWrapper.like("title", title);
        }
        if (author != null && !author.isEmpty()) {
            // 对作者进行模糊查询
            queryWrapper.like("author", author);
        }
        if (category != null && !category.isEmpty()) {
            queryWrapper.like("category", category); // 类别仍使用精确匹配
        }
        return booksTableMapper.selectList(queryWrapper);
    }

    @Override
    public List<BooksTable> queryByCategory(String category) {
        return booksTableMapper.queryByCategory(category);
    }

}
